package com.sumainfor.pc.market.controller.enterprise;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.service.EnterPriseManageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-06-03 15:03
 * 企业客户管理
 */
@RestController
@RequestMapping("/prise/manage/")
public class EnterPriseManageController {

    @Autowired
    private EnterPriseManageService eps;


    /**
     * 查询主页所有的企业列表
     *
     * @return
     */
    @RequestMapping("/selectMainTableList")
    public JsonResult selectMainTableList() {
        return eps.selectMainTableList();
    }

    /**
     * 查询企业房源入住情况 表格数据
     *
     * @param corId
     * @return
     */
    @RequestMapping("/selectHousingTable")
    public JsonResult selectHousingTable(Page page, String corId) {
        if (StringUtils.isBlank(corId)) {
            return JsonResult.errorForEmpty();
        }
        return eps.selectHousingTable(page, corId);
    }

    /**
     * 搜索员工
     *
     * @param phone
     * @param corId
     * @param housingId
     * @return
     */
    @RequestMapping("/queryUserForPhone")
    public JsonResult queryUserForPhone(String phone, String corId, String housingId) {
        if (StringUtils.isBlank(phone) || StringUtils.isBlank(corId) || StringUtils.isBlank(housingId)) {
            return JsonResult.errorForEmpty();
        }
        return eps.queryUserForPhone(phone, corId, housingId);
    }


    /**
     * 确认入住操作
     *
     * @param params
     * @return
     */
    @PostMapping("/confirmCheckIn")
    public JsonResult confirmCheckIn(@RequestBody Map<String, Object> params) {
        String[] key = {"TenId", "CorId", "HouId", "HouInfoId"};
        if (!FieldCheckUtil.isMapFieldNotNull(params, key)) {
            return JsonResult.errorForEmpty();
        }
        return eps.confirmCheckIn(params);
    }


    /**
     * 模糊查询 获得历史入住记录
     *
     * @param page
     * @param username
     * @param phone
     * @return
     */
    @RequestMapping("/selectHistoryLog")
    public JsonResult selectHistoryLog(Page page, String username, String phone) {
        return eps.selectHistoryLog(page, username, phone);
    }

}
